﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Incendios0_1.sms
{
    /// <summary>
    /// Interaction logic for addsmscontact.xaml
    /// </summary>
    public partial class addsmscontact : Window
    {
        Contacts Contact;
        Boolean newContact;

        public addsmscontact()
        {
            InitializeComponent();
            Contact = new Contacts();
            main.DataContext = Contact;
            newContact = true;
        }

        public addsmscontact(Contacts contact)
        {
            InitializeComponent();
            this.Contact = contact;
            main.DataContext = Contact;
            newContact = false;
        }

        private void addsmsmcontact_Click(object sender, RoutedEventArgs e)
        {
            if (newContact)
            {
                ContactControler.AddContact(Contact);
                newContact = false;
            }
            if (!ContactControler.SaveChanges())
            {
                Microsoft.Windows.Controls.MessageBox.Show("El contacto ya existe", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
                Microsoft.Windows.Controls.MessageBox.Show("El contacto ha sido guardado", "Guardar", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        private void cancelsmscontact_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Cancel()
        {
            if (!newContact)
            {
                ContactControler.Cancel(Contact);
            }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Cancel();
        }
    }
}
